use std::collections::*;
use rand::Rng;
use std::{thread, time};
use std::time::{Duration, Instant};
use hashbrown::HashMap as hashbrownHashMap;

use crate::Duration::DurationX;


pub fn hashmap_performance(){
    println!("hashmap 性能比较");
    println!("比较对象：HashMap.");

    hashMap(1_000_000);
    hashbrownHashMap(1_000_000);
}

fn hashMap(len: i32){
    // start
    let now = DurationX::new();

    let mut hashMap = HashMap::new();

    //while-loop
    let mut i=0;
    while(i< len){
        let sn = rand::thread_rng().gen_range(1..=100);
        hashMap.insert(i, sn);
        i+=1;
    }
    println!("hashMap size：{}", hashMap.len());

    let duration = now.release();
    println!("耗时：{}", duration);

    // end

}

fn hashbrownHashMap(len: i32){
    // start
    let now = DurationX::new();


    let mut hashbrownHashMap = hashbrownHashMap::new();

    //while-loop
    let mut i=0;
    while(i< len){
        let sn = rand::thread_rng().gen_range(1..=100);
        hashbrownHashMap.insert(i, sn);
        i+=1;
    }
    println!("hashbrownHashMap size：{}", hashbrownHashMap.len());

    let duration = now.release();
    println!("耗时：{}", duration);

    // end

}